from goods.search_indexes import SKUIndex
from .models import SKU
from rest_framework.serializers import ModelSerializer
from drf_haystack.serializers import HaystackSerializer


class SKUSerializer(ModelSerializer):
    class Meta:
        model = SKU
        fields = ('id', 'comments', 'price', 'name', 'default_image_url')


class SKUIndexSerializer(HaystackSerializer):
    """
    SKU索引结果数据序列化器
    """
    object = SKUSerializer(read_only=True)

    class Meta:
        index_classes = [SKUIndex]
        fields = ('text', 'object')
